//
//  HomeVC.m
//  BasePorject_App
//
//  Created by Yutian Duan on 2019/5/27.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "HomeVC.h"
#import "HomeHeadView.h"
#import "HomeTableView.h"
#import "HomeShowNoticeView.h"

@interface HomeVC ()
@property (nonatomic, strong) HomeHeadView *homeHeadView;
@property (nonatomic, strong) HomeTableView *tableView;


@end

@implementation HomeVC

- (HomeHeadView *)homeHeadView {
  if (!_homeHeadView) {
    _homeHeadView = [[HomeHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
    __weak typeof(self) weakSelf = self;
    _homeHeadView.clickLoginBlock = ^{
      [weakSelf clickVip];
    };
  
  }
  return _homeHeadView;
}

- (void)viewDidLoad {
  [super viewDidLoad];

}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:YES animated:animated];
  [self setStatusBarStyleWhite];
}

- (void)createFields {
  [super createFields];
  
}

- (void)createViews {
  [super createViews];
  self.view.backgroundColor = [UIColor blackColor];
  
  _tableView = [[HomeTableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - TabBarHeight) style:UITableViewStylePlain];
  _tableView.tableHeaderView = self.homeHeadView;
  [self.view addSubview:_tableView];

}

- (void)loadData {
  [super loadData];
  
  
  
  _tableView.data = @[@"",@"",@""];
  [self.homeHeadView reloadData];
  [_tableView reloadData];
  
  [self showNoticeView];
}

- (void)showNoticeView {
  
  HomeShowNoticeView *noticeView = [HomeShowNoticeView noticeView];
  
  [noticeView showWithClose:^(BOOL isPass) {
    if (isPass) {
      NSURL * settingUrl = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
      if ([[UIApplication sharedApplication] canOpenURL:settingUrl]){
        [[UIApplication sharedApplication] openURL:settingUrl];
      }
    }
    
    
  }];
  
  
}

- (void)clickVip {
  if ([ToolsServer sharedInstance].isLoginApp == YES) {
    
  } else {
    [self goLogin];
  }
}


@end
